//引入接口
import API from '../../config/server.js'
Page({
  data:{
    hero:{},
    imgList:[]
  },
  onLoad(option)
  {
    // console.log(option)
    let id = option.id
    let url = option.url
    this.getInfo(id,url)
  },
  getInfo(id,url){
    let that=this
    wx.showLoading({
      title: '加载中...',
    })
    wx.request({
      url: API.herodetail,
      data: {id,url},
      header: {},
      method: 'POST',
      dataType: 'json',
      responseType: 'text',
      success: function(res) {
        let data=res.data
        if(data.success){
          that.setData({ hero: data.data})
          var imgArr=data.data.heroDetail.filter(function(item,i){
            return item.type=='img'
          })
          // console.log(imgArr)
          var trueArr=[]
          imgArr.forEach(function(item,i){
            trueArr.push(item.text)
          })
          // console.log(trueArr)
          that.setData({ imgList: trueArr})
        }
      },
      fail: function(res) {
        wx.showToast({
          title: '网络错误',
          icon: 'error',
        })
      },
      complete: function(res) {
        wx.hideLoading()
      },
    })
  },
  previewImg(e){
    var url = e.currentTarget.dataset.url
    var imgList = this.data.imgList
    wx.previewImage({
      current: url,
      urls: imgList
    })
  },
  showHistory(){
    wx.showModal({
      title: this.data.hero.historyTitle,
      content: this.data.hero.historyContent,
      showCancel: false,
    })
  }
})